home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3096 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Floating point calculation order
  5. Date: Thu, 25 Jan 96 20:06:31 GMT
  6. Organization: none
  7. Message-ID: <822600391snz@genesis.demon.co.uk>
  8. References: <m0tedv8-0002eqC@sice.nsk.su> <3104c6d9.134061184@nntp.ix.netcom.com> <TANMOY.96Jan23144637@qcd.lanl.gov> <DLpF0C.IH4@microunity.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <DLpF0C.IH4@microunity.com> toms@MicroUnity.com "Tom Sanders" writes:
  15.  
  16. >As to the original equation `p * q / r' , I would argue that parentheses
  17. >are certainly necessary.  There is a slight numeric difference between
  18. >`(p * q) / r' and `p * (q / r)' .  By specifying I am sure the order I
  19. >prefer will be used no matter what compiler I am using.
  20.  
  21. If a compiler is broken enough to evaluate p * q / r as p * (q / r) it is
  22. likely to evaluate (p * q) / r the same way (since in C they have always
  23. meant exactly the same thing and parentheses are unlikely to have any effect
  24. in the compiler beyond the initial syntax parsing stage). So the *only*
  25. reason for using parentheses in this case is readability. If you want to
  26. pander to non-standard/broken compilers you would have to write it as
  27. something like:
  28.  
  29.    tmp = p * q, tmp / r
  30.  
  31. -- 
  32. -----------------------------------------
  33. Lawrence Kirby | fred@genesis.demon.co.uk
  34. Wilts, England | 70734.126@compuserve.com
  35. -----------------------------------------
  36.